package com.dc.refactoring._3_重新组织数据._7_ChangeBidirectionalAssociationToUnidirectional.step1;


/**
 * Description: 存在双向关联的 订单类
 * @author: gdc
 * @date: 2020/11/17
 * @version 1.0
 */
public class Order {
    /**
     * 客户类引用
     */
    private Customer customer;

    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer arg) {
        if (customer != null) {
            customer.friendOrders().remove(this);
        }
        customer = arg;
        if (customer != null) {
            customer.addOrder(this);
        }
    }



    private double grossPrice = 0;

    public double getGrossPrice() {
        return grossPrice;
    }

    public void setGrossPrice(double grossPrice) {
        this.grossPrice = grossPrice;
    }

    public double getDiscountedPrice() {
        return getGrossPrice() * (1 - customer.getDiscount());
    }
}
